<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD']."Aplications/ReportModels/report.vars.php");
MYTCONN();
	include($GLOBALS['OBJ'].'obj.mathgrids.mex');
	$NoResults = '<tr bgcolor="#F2F2F2"><td colspan="33">Não existem resultados para apresentação.</td></tr>';

	$FinantialResult = 0;
	if(empty($_POST)){
		$_POST['Tini'] = date("Y-m-01");
		$_POST['Tend'] = date("Y-m-d");
		$_POST['Origens'] = 'OrderOffice';
		$_POST['Countries'] = '301,305,300';
	}

	$Tini = $_POST['Tini'];
	$Tend = $_POST['Tend'];

	$NClCountry = " AND BnfPais = 76";
	$QrCountry = " AND FraCorresponsal IN ({$_POST['Countries']})";
	$ClCountry = " AND BnfPais = 76";
	$currency = '';
	echo $tablehead;
	echo '<tr align="center">
	<td colspan="33" height="22px" bgcolor="#FFFFFF">Distribuição da actividade de captação de remessas por horas no periodo entre '.$Tini.' e '.$Tend.'</td></tr>
	<tr align="center" bgcolor="#D7E3E8" height="24px">
	<td width="17%">Loja</td>';
	for($i=1;$i<=24;$i++) {
	echo '<td width="3%">'.($i-1).'-'.$i.'h</td>';
	}
	echo '</tr>';

	$GET = $GLOBALS['MYT']->db_array("SELECT OriNombre,
		SUM(IF(HOUR(FraFechaIngreso)=0,1,0)) AS Card1,
		SUM(IF(HOUR(FraFechaIngreso)=1,1,0)) AS Card2,
		SUM(IF(HOUR(FraFechaIngreso)=2,1,0)) AS Card3,
		SUM(IF(HOUR(FraFechaIngreso)=3,1,0)) AS Card4,
		SUM(IF(HOUR(FraFechaIngreso)=4,1,0)) AS Card5,
		SUM(IF(HOUR(FraFechaIngreso)=5,1,0)) AS Card6,
		SUM(IF(HOUR(FraFechaIngreso)=6,1,0)) AS Card7,
		SUM(IF(HOUR(FraFechaIngreso)=7,1,0)) AS Card8,
		SUM(IF(HOUR(FraFechaIngreso)=8,1,0)) AS Card9,
		SUM(IF(HOUR(FraFechaIngreso)=9,1,0)) AS Card10,
		SUM(IF(HOUR(FraFechaIngreso)=10,1,0)) AS Card11,
		SUM(IF(HOUR(FraFechaIngreso)=11,1,0)) AS Card12,
		SUM(IF(HOUR(FraFechaIngreso)=12,1,0)) AS Card13,
		SUM(IF(HOUR(FraFechaIngreso)=13,1,0)) AS Card14,
		SUM(IF(HOUR(FraFechaIngreso)=14,1,0)) AS Card15,
		SUM(IF(HOUR(FraFechaIngreso)=15,1,0)) AS Card16,
		SUM(IF(HOUR(FraFechaIngreso)=16,1,0)) AS Card17,
		SUM(IF(HOUR(FraFechaIngreso)=17,1,0)) AS Card18,
		SUM(IF(HOUR(FraFechaIngreso)=18,1,0)) AS Card19,
		SUM(IF(HOUR(FraFechaIngreso)=19,1,0)) AS Card20,
		SUM(IF(HOUR(FraFechaIngreso)=20,1,0)) AS Card21,
		SUM(IF(HOUR(FraFechaIngreso)=21,1,0)) AS Card22,
		SUM(IF(HOUR(FraFechaIngreso)=22,1,0)) AS Card23,
		SUM(IF(HOUR(FraFechaIngreso)=23,1,0)) AS Card24

FROM facturas
  INNER JOIN origenes ON OriNumero = FraOrigen0
  WHERE FraID > 400000 AND FraFechaIngreso BETWEEN '{$Tini}' AND '{$Tend}' AND FraStatus NOT IN (1,10,21)
GROUP BY FraOrigen0");

	$CGET = $GET[0]+1;
if (!isset($GET[1])) {
	echo $NoResults;
} else {
	for($h = 1; $h <= $CGET; $h++) {

    echo '<tr  height="18px" bgcolor="'.gridlines($h).'"</td>
	<td NOWRAP>'.FieldResult($GET,$h,'OriNombre').'</td>';
	for($i=1;$i<=24;$i++) {
	echo '<td align="right">'.FieldResult($GET,$h,'Card'.$i).'</td>';
	}
	echo '</tr>';
	}
} ?>